package com.ljh.account.controller;

import com.github.pagehelper.PageInfo;
import com.ljh.account.dao.Req.SaveMoneyReq;
import com.ljh.account.dao.WishWall;
import com.ljh.account.service.WishWallService;
import com.ljh.account.utils.Response;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/protected")
public class WishWallController {

    @Autowired
    private WishWallService wishWallService;

    @PostMapping("/wishes")
    public Response createWish(HttpServletRequest request,@RequestBody WishWall wish) {
        Object userId = request.getAttribute("userId");
        wish.setUserId((Long) userId);
        wishWallService.createWish(wish);
        return  Response.success("添加心愿墙成功");
    }

    @PutMapping("/wishes")
    public Response updateWish(@RequestBody SaveMoneyReq params) {
        wishWallService.saveMoney(params);
        return Response.success("新增成功！");
    }

    @DeleteMapping("/wishes")
    public void deleteWish(@RequestParam("id") Integer wishId) {
        wishWallService.deleteWish(wishId);
    }

    @GetMapping("/wishes")
    public Response getAllWishesByUserId(HttpServletRequest request, @RequestParam int page, @RequestParam int size) {
        Object userId = request.getAttribute("userId");
        PageInfo res = wishWallService.getAllWishesByUserId((Long) userId, page, size);
         return Response.success(res);
    }

}